package com.szqhyxj.youxiangju.biz.card.cardApply;

import com.szqhyxj.youxiangju.biz.card.CardModel;
import com.szqhyxj.youxiangju.sys.BaseResult;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by leung on 2018/11/3.
 */

public class CardApplyPresenter implements CardApplyContract.Presenter{
    CardApplyContract.View view;

    public CardApplyPresenter(CardApplyContract.View view) {
        this.view = view;
    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void getCardList() {

     CardApplyModel.getCardApply()
             .subscribeOn(Schedulers.io())
             .observeOn(AndroidSchedulers.mainThread())
             .subscribe(new Consumer<BaseResult<List<CardApplyModel.CardApplyEntity>>>() {
                 @Override
                 public void accept(BaseResult<List<CardApplyModel.CardApplyEntity>> listBaseResult) throws Exception {
                     if (listBaseResult.businessLogicSuccess()){
                         view.showList(listBaseResult.getData());
                     }else {
                         view.showFail(listBaseResult.getMessage());
                     }

                 }
             }, new Consumer<Throwable>() {
                 @Override
                 public void accept(Throwable throwable) throws Exception {
                   view.showFail(throwable.getMessage());
                 }
             });
    }
}
